package com.highcom.controller;


import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@Controller
@SessionAttributes(names = {"age","gender"})
public class UserController {

    //获取原生 request response session
    @RequestMapping("/servletApi")
    public  String servletApi(HttpServletRequest request,
                              HttpServletResponse response, HttpSession session){
        System.out.println(request);
        System.out.println(response);
        System.out.println(session);
        return "page";
    }
    @RequestMapping("/headApi") //@CookieValue
    public  String headApi(@RequestHeader("Accept-Language") String headMsg){
        System.out.println(headMsg);
        return "page";
    }
    @RequestMapping("/setSession") //@CookieValue
    public  String setSessionData(HttpSession session){
        session.setAttribute("name","tom");
        return "page";
    }

    //@SessionAttributes(names = {"age","gender"})
    @RequestMapping("/setSession2") //@CookieValue
    public  String setSessionData2(Model model){

        model.addAttribute("age",39);
        model.addAttribute("gender","男");
        return "page";
    }

}
